package com.glorystone.ins.enums;

import java.util.List;

/**
 * @author liuming
 * @date 2017年11月6日 下午6:25:22
 */
public enum CreditError {
  PARAM_ERROR(4001, "param.error"),
  OTHER_METHOD_ARGS_NOT_VALID(9000, ""), 
  OTHER_HTTP_MEDIATYPE_NOT_SUPPORT(9001, "other.contenttype.unsupport"), 
  OTHER_HTTP_MESSAGE_NOT_READABLE(9002, "other.message.not.readable"), 
  OTHER_HTTP_TYPE_MISMATCH(9003, "other.type.mismatch"), 
  OTHER_SERVER_INERNAL_EXCEPTION(9999, "other.server.internal.error");

  private int errorCode;
  private String messageKey;

  CreditError(final int code, final String messageKey) {
    this.errorCode = code;
    this.messageKey = messageKey;
  }

  public int getErrorCode() {
    return this.errorCode;
  }

  public String getMessageKey() {
    return this.messageKey;
  }

  public static CreditError of(final int errorCode) {
    CreditError appError = null;
    for (final CreditError error : values()) {
      if (error.getErrorCode() == errorCode) {
        appError = error;
      }
    }

    return appError;
  }

}
